﻿<Window xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"  x:Class="centraldba_dbrestore_utility.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:centraldba_dbrestore_utility"
        mc:Ignorable="d"
        Icon="/centraldba_dbrestore_utility;component/Resources/1318623277_database_refresh.ico" 
        Title="Database Restore Utility" Height="550" Width="750">
    <Window.Resources>
        <Style x:Key="Body_Content_DataGrid_Centering" TargetType="{x:Type DataGridCell}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type DataGridCell}">
                        <Grid Background="{TemplateBinding Background}">
                            <ContentPresenter VerticalAlignment="Center" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="Body_Content_DataGrid_RightAlign" TargetType="{x:Type DataGridCell}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type DataGridCell}">
                        <Grid Background="{TemplateBinding Background}">
                            <ContentPresenter HorizontalAlignment="Right" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="DataGridRow">
            <Style.Triggers>
                <DataTrigger Binding="{Binding file_exists}" Value="False">
                    <Setter Property="Background" Value="Maroon" />
                    <Setter Property="Foreground" Value="LightGray" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <DockPanel>
        <ToolBarTray DockPanel.Dock="Top">
            <ToolBar Name="Filter">
                <Border BorderThickness="1" BorderBrush="Gainsboro" CornerRadius="3" ToolBar.OverflowMode="AsNeeded">
                    <WrapPanel Orientation="Vertical" Height="35" Margin="4">
                        <RadioButton Name="TodayDate" Content="Today      " GroupName="DateFilter" Margin="1" IsChecked="True" Click="TodayDate_Click" />
                        <RadioButton Name="AllFiles" Content="All Files  " GroupName="DateFilter" Margin="1" Click="RadioButton_Click" />
                        <RadioButton Name="RecoveryWindow" Content="Recovery Window" GroupName="DateFilter" Margin="1" Click="RadioButton_Click" />
                        <RadioButton Name="CustomDate" Content="Custom Date... " GroupName="DateFilter" Margin="1" Click="CustomDate_Click" />
                    </WrapPanel>
                </Border>
                <Border BorderThickness="1" BorderBrush="Gainsboro" CornerRadius="3" ToolBar.OverflowMode="Always">
                    <StackPanel Orientation="Vertical" Margin="5">
                        <CheckBox Name="bkpFileExists" IsChecked="True" Margin="2" ToolTip="Display only backup files that exist?" HorizontalAlignment="Center" Click="RadioButton_Click" />
                        <Label Content="File Exists?" HorizontalAlignment="Center" />
                    </StackPanel>
                </Border>
                <Border BorderThickness="1" BorderBrush="Gainsboro" CornerRadius="3" ToolBar.OverflowMode="Always">
                    <StackPanel Orientation="Vertical" Margin="5">
                        <Label Content="Stop at Time?" HorizontalAlignment="Center" />
                        <xctk:DateTimePicker x:Name="stopat_time" 
                                                   Margin="3"
                                                   Format="Custom" 
                                                   FormatString="MM/dd/yy hh:mm:ss tt" />
                    </StackPanel>
                </Border>
            </ToolBar>
            <ToolBar Name="Commands" >
                <Button Name="cmdRestore" ToolBar.OverflowMode="Never" ToolTip="Restore the Database" Click="cmdRestore_Click" IsEnabled="False">
                    <StackPanel Orientation="Vertical">
                        <Image Source="/centraldba_dbrestore_utility;component/Resources/arrow_run_16xLG.png" />
                        <TextBlock Margin="3,0,0,0">Restore</TextBlock>
                    </StackPanel>
                </Button>
                <Button Name="cmdScript" ToolBar.OverflowMode="Never" ToolTip="Create a Restore Script" Click="cmdScript_Click" IsEnabled="False">
                    <StackPanel Orientation="Vertical">
                        <Image Source="/centraldba_dbrestore_utility;component/Resources/script_16xLG.png" />
                        <TextBlock Margin="3,0,0,0">Script</TextBlock>
                    </StackPanel>
                </Button>
                <Button Name="cmdConfigure" ToolBar.OverflowMode="AsNeeded" ToolTip="Configure" Click="cmdConfigure_Click">
                    <StackPanel Orientation="Vertical">
                        <Image Source="/centraldba_dbrestore_utility;component/Resources/properties_16xLG.png" />
                        <TextBlock Margin="3,0,0,0">Configure</TextBlock>
                    </StackPanel>
                </Button>
                <Button Name="cmdAbout" ToolBar.OverflowMode="AsNeeded" ToolTip="About" Click="cmdAbout_Click">
                    <StackPanel Orientation="Vertical">
                        <Image Source="/centraldba_dbrestore_utility;component/Resources/StatusAnnotations_Help_and_inconclusive_16xLG_color.png" />
                        <TextBlock Margin="3,0,0,0">About</TextBlock>
                    </StackPanel>
                </Button>
            </ToolBar>
        </ToolBarTray>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Border Grid.Row="0" Grid.ColumnSpan="2" BorderThickness="1" BorderBrush="Gainsboro" CornerRadius="3" Background="AliceBlue" Padding="5" />

            <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Vertical" Margin="3">
                <ComboBox Name="SourceConnection" DisplayMemberPath="connection" SelectedValue="connection" SelectionChanged="SourceConnection_SelectionChanged" />
                <Label Content="Source Connection" HorizontalAlignment="Center" Foreground="DarkGray" Margin="0" />
            </StackPanel>
            <StackPanel Grid.Row="0" Grid.Column="1" Orientation="Vertical" Margin="3">
                <ComboBox Name="DestinationConnection" DisplayMemberPath="connection" SelectedValue="connection" SelectionChanged="DestinationConnection_SelectionChanged" />
                <Label Content="Destination Connection" HorizontalAlignment="Center" Foreground="DarkGray" Margin="0" />
            </StackPanel>

            <xctk:BusyIndicator Name="busyDatabaseBackups" BusyContent="Loading Backup Data..." Grid.Row="1" Grid.ColumnSpan="2">
                <DataGrid x:Name="dgDatabaseBackups" 
                      ItemsSource="{Binding}" 
                      CellStyle="{StaticResource ResourceKey=Body_Content_DataGrid_Centering}"
                      AutoGenerateColumns="False" 
                      IsReadOnly="True" 
                      SelectionUnit="FullRow"
                      SelectionMode="Single"
                      CanUserReorderColumns="False" 
                      CanUserSortColumns="True"
                      GridLinesVisibility="None"
                      Margin="2" SelectedCellsChanged="dgDatabaseBackups_SelectedCellsChanged">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="ID" 
                                    Binding="{Binding id}" />
                        <DataGridTextColumn Header="Label" 
                                    Binding="{Binding name}" />
                        <DataGridTextColumn Header="Bkp Type" 
                                    Binding="{Binding type_description}" />
                        <DataGridTextColumn Header="Started"
                                    Binding="{Binding backup_start_date, StringFormat={}{0:MM/dd/yy hh:mm:ss tt}}" />
                        <DataGridTextColumn Header="Size" 
                                    Binding="{Binding backup_size, StringFormat={}{0:N0}}" CellStyle="{StaticResource ResourceKey=Body_Content_DataGrid_RightAlign}" />
                        <DataGridTextColumn Header="Bkp ID" 
                                    Binding="{Binding backup_set_id}" />
                        <DataGridTextColumn Header="Database" 
                                    Binding="{Binding database_name}" />
                        <DataGridCheckBoxColumn Header="Bulk Data?" 
                                        Binding="{Binding has_bulk_logged_data}" />
                        <DataGridCheckBoxColumn Header="Rec Path Broken?" 
                                        Binding="{Binding recovery_path_broken}" />
                        <DataGridCheckBoxColumn Header="File Exists?" 
                                        Binding="{Binding file_exists}" />
                        <DataGridTextColumn Header="File path" 
                                    Binding="{Binding physical_device_name}" />
                    </DataGrid.Columns>
                </DataGrid>
            </xctk:BusyIndicator>
        </Grid>
    </DockPanel>
</Window>
